package com.ccjq.shosestore.web.controller.order;

import com.ccjq.shosestore.core.domain.PageInfo;
import com.ccjq.shosestore.order.po.OrderPo;
import com.ccjq.shosestore.order.service.impl.OrderServiceImpl;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "FengServlet")
public class FengServlet extends HttpServlet {
    private static final String FALG_ZHIFU="zhifu";//结算购物车
    private static final String FALG_SELECT = "selectorder";//查询订单
    private static final String FALG_SELECTORDER= "selectorder_id";//根据订单id查询具体数据
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        HttpSession session = request.getSession();
        String userId = (String) session.getAttribute("userId");//用户的登录信息（id）
        String falg = request.getParameter("falg");
        System.out.println(falg);
        OrderServiceImpl orderImpl = new OrderServiceImpl();
        if(StringUtils.isNotBlank(userId)){
                PageInfo<OrderPo> pageInfo = null;
                int pageSizes = 0;
                int pageNos = 0;
                String pageSize   = request.getParameter("pageSize");//每页显示的行数
                String pageNo     = request.getParameter("pageNo"); //当前页
                if( StringUtils.isBlank(pageSize)){
                    pageSizes=6;
                }else {
                    pageSizes =Integer.parseInt(pageSize);
                }
                if(StringUtils.isBlank(pageNo)){
                    pageNos=1;
                }else {
                    pageNos = Integer.parseInt(pageNo);
                }
                pageInfo = orderImpl.selectFengYeAll(userId,pageSizes,pageNos);
                List<OrderPo> listCar = pageInfo.getObjs();
                //request.setAttribute("pageInfo",pageInfo);
                request.setAttribute("listCar",listCar);
                request.getRequestDispatcher("/WEB-INF/jsp/order/order_list.jsp").forward(request,response);

        }else{
            request.getRequestDispatcher("/WEB-INF/jsp/member/login.jsp").forward(request,response);
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
